//
//  HQCollectionViewController.m
//  Dsgfds
//
//  Created by lanou on 15/10/24.
//  Copyright © 2015年 胡泉. All rights reserved.
//

#import "HQCollectionViewController.h"
#import "HQCircleLayout.h"
#import "HQCollectionViewCell.h"
@interface HQCollectionViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UIImageView *endImageView;
@property (weak, nonatomic) IBOutlet UIImageView *textImageView;
@property (weak, nonatomic) IBOutlet UIImageView *titleImageView;
@property (weak, nonatomic) IBOutlet UICollectionView *gridView;
@property (nonatomic, assign) NSInteger cellCount;
@property (nonatomic, strong) NSArray *dataArray;


@end

@implementation HQCollectionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    HQCircleLayout *circleLayout = [[HQCircleLayout alloc] init];
    self.gridView.collectionViewLayout = circleLayout;
    self.gridView.backgroundColor = [UIColor whiteColor];
    _gridView.dataSource = self;
    _gridView.delegate = self;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    [_gridView addGestureRecognizer:tap];
    UINib *nib = [UINib nibWithNibName:@"HQCollectionViewCell" bundle:nil];
    [self.gridView registerNib:nib forCellWithReuseIdentifier:@"cellId"];
    // 设置中心imageView
    UITapGestureRecognizer *tapCenter = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapCenter:)];
    [_textImageView addGestureRecognizer:tapCenter];
    
    _titleImageView.image = [UIImage imageNamed:@"bai"];
    _endImageView.image = [UIImage imageNamed:@"wei"];
    
    _textImageView.image = [UIImage imageNamed:@"meiwen.jpg"];
    _textImageView.layer.cornerRadius = 70;
    _textImageView.layer.masksToBounds = YES;
    _textImageView.contentMode = UIViewContentModeScaleToFill;
    _textImageView.userInteractionEnabled = YES;
    self.dataArray = @[@{@"image":@"meishi.jpg",@"id":@9},@{@"image":@"wenhua.jpg",@"id":@11},@{@"image":@"shishang.jpg",@"id":@15},@{@"image":@"kongjian.jpg",@"id":@16},@{@"image":@"qiche.jpg",@"id":@18},@{@"image":@"jianzhu.jpg",@"id":@19},@{@"image":@"shuma.jpg",@"id":@20},@{@"image":@"quwu.jpg",@"id":@21}];
  

    
    // Do any additional setup after loading the view from its nib.
}



- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _dataArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    HQCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellId" forIndexPath:indexPath];
    cell.hqImageView.image = [UIImage imageNamed:_dataArray[indexPath.item][@"image"]];
    return cell;
}

- (void)handleTapCenter:(UITapGestureRecognizer *)sender
{
    NSLog(@"ada");
}

- (void)handleTap:(UITapGestureRecognizer *)sender
{
    // 判断是否点击结束
    if (sender.state == UIGestureRecognizerStateEnded) {
    // 获取点击点的位置
        CGPoint clickPoint = [sender locationInView:self.gridView];
        NSIndexPath *indexPath = [self.gridView indexPathForItemAtPoint:clickPoint];
        // 如果被点击的单元格存在
        if (indexPath)
        {
            // 删除单元格
//            _cellCount --;
//            [self.gridView deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
            NSLog(@"1");
        }
        // 如果点击的空白处
        else
        {
//            _cellCount ++;
//            [self.gridView insertItemsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForItem:0 inSection:0]]];
            NSLog(@"2");
        }
        
    }
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
